package com.gwcloud.leetcode.hot100;

import java.util.Arrays;

/** 
* @ClassName   : Leetcode0621 
* @author      : ganwei 
* @date        : 2020年5月24日 
* @Description : TODO 
*/
public class Leetcode0621 {
    /**
     * -解题思路
     */
	public int leastInterval(char[] tasks, int n) {
		if(tasks.length <= 1 || n < 1) {
			return tasks.length;
		}
		
		int[] counts = new int[26];
		for(int i = 0; i < tasks.length; i++) {
			counts[tasks[i] - 'A']++; 
		}
		
		Arrays.sort(counts);
		int maxCount = counts[25];
		int retCount = (maxCount-1) * (n+1) + 1;
		int i = 24;
		
		while(i>=0 && counts[i] == maxCount) {
			retCount++;
			i--;
		}
		
    	return Math.max(retCount, tasks.length);
    }
	/**
	 * -主函数
	 */
	public static void main(String[] args) {
		
	}
}
